package com.wyutil.wy_FileFormatConversion.pdfWithOther;

import com.spire.pdf.PdfDocument;
import org.junit.Test;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

public class PdfWithImage {

    /**
     * 这些都是可以进行修改的。
     * @param pdfPath pdf 的文件路径
     * @param outPath  输出图片的路径
     */
    @Test
    public void convert(String pdfPath,String outPath) throws IOException {
        PdfDocument pdf = new PdfDocument(pdfPath);
        BufferedImage image;
        for(int i = 0; i< pdf.getPages().getCount();i++){
            image = pdf.saveAsImage(i);
            File file = new File(outPath+"\\img-" + i);
            ImageIO.write(image, "PNG", file);
        }
        pdf.close();
    }
}
